'use strict';
const svgCaptcha = require('svg-captcha');

module.exports = app => {
 class CommonService extends app.Service {
    captcha(){
        const captcha = svgCaptcha.create({
            size: 4,
            fontSize: 50,
            width: 160,
            height: 50,
            ignoreChars: '0oO1ilI', // 验证码字符中排除 0o1i
            noise: 2, // 干扰线条的数量
            color: true, // 验证码的字符是否有颜色，默认没有，如果设定了背景，则默认有
            bacground: '#cc9966'
        })
        this.ctx.session.code = captcha.text;
        return captcha;
    }

    async login(query){
        const {ctx} = this;
        try {
            const result = await ctx.model.Users.findOne({
                where:{
                    userName: query.userName
                },
                // include:
            })
            return result
        } catch (error) {
            return ctx.throw(500,'获取用户信息失败')
        }

    }
 }
 return CommonService;
};

